package com.l.im.init;

/**
 * @program: LIM
 * @description:
 * @author: Alex Wu
 * @createDate: 2025-04-14 17:59
 **/
import com.l.im.handler.HttpRequestHandler;
import com.l.im.strategy.RouteStrategy;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;

import java.util.List;

public class HttpGatewayInitializer extends ChannelInitializer<SocketChannel> {

    private final RouteStrategy routeStrategy;
    private final List<String> servers;

    // 设置服务器列表
    public HttpGatewayInitializer(RouteStrategy routeStrategy, List<String> servers) {
        this.routeStrategy = routeStrategy;
        this.servers = servers;
    }

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline().addLast(new HttpServerCodec());
        ch.pipeline().addLast(new HttpObjectAggregator(65536));
        HttpRequestHandler handler = new HttpRequestHandler(routeStrategy, servers);
        ch.pipeline().addLast(handler);
    }
}
